#lang rosetta-racket


(require "lego.rkt")

(provide lego-giant-panda-example)


(define 2x1x1 (make-xyz-brick 2 1 1))
(define 3x1x1 (make-xyz-brick 3 1 1))
(define 4x1x1 (make-xyz-brick 4 1 1))
(define 6x1x1 (make-xyz-brick 6 1 1))

(define 1x2x1 (make-xyz-brick 1 2 1))
(define 2x2x1 (make-xyz-brick 2 2 1))
(define 4x2x1 (make-xyz-brick 4 2 1))
(define 8x2x1 (make-xyz-brick 8 2 1))

(define 1x3x1 (make-xyz-brick 1 3 1))

(define 1x4x1 (make-xyz-brick 1 4 1))
(define 2x4x1 (make-xyz-brick 2 4 1))

(define 2x8x1 (make-xyz-brick 2 8 1))


(define grass-pos (xy 5 6))
(define grass-size (xy 10 10))


(define (lego-giant-panda)
  (lego
   (make-grid-world (xy 20 21))
   
   ; grass
   (lay (make-xyz-brick (xyz-x grass-size) (xyz-y grass-size) 1) grass-pos)
   
   (with-world-cs
    grass-pos
    
    (with-world-size
     grass-size
     
     ; front legs
     (lay-x-sym 2x2x1 (xy 1 1))
     (lay-x-sym 2x2x1 (xy 1 2))
     (lay-x-sym 2x2x1 (xy 1 2))
     (lay-x-sym 2x2x1 (xy 1 2))
     
     ; back legs
     (lay-x-sym (back 2x2x1) (back-xy 1 1))
     (lay-x-sym (back 2x1x1) (back-xy 1 0))
     (lay-x-sym (back 2x2x1) (back-xy 1 0))
     (lay-x-sym (back 2x2x1) (back-xy 1 0))
     (lay-x-sym (back 2x2x1) (back-xy 1 0)))
    
    ; belly 1
    (put 2x2x1 (xyz 4 1 4))
    (put 4x2x1 (xyz 3 3 4))
    (put 4x2x1 (xyz 3 5 4))
    (put 4x2x1 (xyz 3 7 4))
    (put 2x1x1 (xyz 4 9 4))
    
    (with-world-size
     grass-size
     
     ; belly 2
     (lay-x-sym 4x1x1 (xy 1 1))
     (lay 8x2x1 (xy 1 2))
     (lay-x-sym 2x4x1 (xy 2 4))
     (lay 8x2x1 (xy 1 8))
     
     ; belly 3
     (lay-x-sym 1x3x1 (xy 1 1))
     (lay-x-sym 1x1x1 (xy 2 1))
     (lay-x-sym 1x4x1 (xy 2 2))
     (lay-x-sym 1x4x1 (xy 2 6))
     (lay-x-sym 1x2x1 (xy 1 8))
     (lay 4x2x1 (xy 3 9)))
    
    ; head 1
    (put 2x1x1 (xyz 4 -5 5))
    (put 2x4x1 (xyz 3 -4 5))
    (put 2x4x1 (xyz 5 -4 5))
    (put 2x1x1 (xyz 4 0 5))
    
    (with-world-size
     grass-size
     
     ; head 2
     (lay 2x4x1 (xy 4 -6))
     (lay-x-sym 1x2x1 (xy 3 -5))
     (lay-x-sym 2x2x1 (xy 2 -3))
     (lay 2x1x1 (xy 4 -2))
     (lay-x-sym 2x4x1 (xy 3 -1))
     
     ; head 3
     (lay 2x1x1 (xy 4 -6))
     (lay 4x1x1 (xy 3 -5))
     (lay-x-sym 2x4x1 (xy 2 -4))
     (lay 2x2x1 (xy 4 -4))
     (lay 2x4x1 (xy 4 -2))
     
     ; middle 1
     (lay-x-sym 2x2x1 (xy 2 0))
     (lay-x-sym 1x3x1 (xy 1 1))
     (lay-x-sym 1x3x1 (xy 2 2))
     (lay-x-sym 1x4x1 (xy 2 5))
     (lay-x-sym 1x2x1 (xy 1 8))
     (lay-x-sym 2x2x1 (xy 2 9))
     (lay 2x2x1 (xy 4 10))
     
     ; middle 2
     (lay 2x1x1 (xy 4 -5))
     (lay-x-sym 1x1x1 (xy 2 -4))
     (lay 4x2x1 (xy 3 -4))
     (lay-x-sym 1x4x1 (xy 2 -3))
     (lay 4x2x1 (xy 3 -2))
     (lay 4x2x1 (xy 3 0))
     (lay-x-sym 2x2x1 (xy 1 1))
     (lay-x-sym 2x1x1 (xy 1 3))
     (lay-x-sym 1x4x1 (xy 2 4))
     (lay-x-sym 2x2x1 (xy 1 8))
     (lay 4x2x1 (xy 3 9))
     (lay-x-sym 1x1x1 (xy 2 10))
     (lay 2x1x1 (xy 4 11))
     
     ; back 1
     (lay-x-sym 2x1x1 (xy 2 -4))
     (lay 2x2x1 (xy 4 -4))
     (lay-x-sym 2x4x1 (xy 2 -3))
     (lay 8x2x1 (xy 1 1))
     (lay-x-sym 1x1x1 (xy 1 3))
     (lay-x-sym 2x8x1 (xy 2 3))
     (lay-x-sym 1x2x1 (xy 1 8))
     (lay 2x2x1 (xy 4 9))
     
     ; back 2
     (lay 4x2x1 (xy 3 -4))
     (lay-x-sym 1x3x1 (xy 2 -3))
     (lay 4x2x1 (xy 3 -2))
     (lay 4x2x1 (xy 3 0))
     (lay-x-sym 1x3x1 (xy 2 1))
     (lay-x-sym 1x1x1 (xy 1 2))
     (lay-x-sym 2x8x1 (xy 3 2))
     (lay-x-sym 1x3x1 (xy 2 4))
     (lay-x-sym 1x3x1 (xy 2 7))
     (lay 4x1x1 (xy 3 10)))
    
    ; back 3
    (lay 4x2x1 (xy 3 -3))
    (lay 2x1x1 (xy 4 0))
    (lay 4x1x1 (xy 3 1))
    (lay 6x1x1 (xy 2 2))
    (lay 4x1x1 (xy 3 3))
    (lay 4x2x1 (xy 3 4))
    (lay 4x2x1 (xy 3 6))
    (lay 4x2x1 (xy 3 8))
    
    ; back 4
    (lay 2x1x1 (xy 4 2))
    (lay 2x4x1 (xy 4 3))
    (lay 2x2x1 (xy 4 7))
    
    ; ears
    (with-world-size
     grass-size
     (lay-x-sym 2x1x1 (xy 1 -1))
     (lay-x-sym 2x1x1 (xy 1 -1))))))

(define (lego-giant-panda-example)
  (view
   (xyz 264.27051507000397 -124.74905290880376 105.79741353475598)
   (xyz 65.0888246389592 95.01040141622651 26.79512926943328)
   (perspective 30)
   (lego-giant-panda)))